package com.spirng.leetcode.day03;

public class CanConstruct {
    public boolean canConstruct(String ransomNote, String magazine) {
        int [] arr1=new int[26];
        for (int i = 0; i < magazine.length(); i++) {
            arr1[magazine.charAt(i)-'a']++;
        }
        for (int i = 0; i < ransomNote.length(); i++) {
            arr1[ransomNote.charAt(i)-'a']--;
            if(arr1[ransomNote.charAt(i)-'a']<0){
                return false;
            }
        }
        return true;
    }
    public boolean canConstruct1(String ransomNote, String magazine) {
        int[] cnt = new int[26];
        for (char c:magazine.toCharArray())
            cnt[c - 'a']++;
        for (char c:ransomNote.toCharArray()){
            if (--cnt[c - 'a'] < 0)
                return false;
        }
        return true;
    }
}
